<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" href="css/style.css" />
		<link rel="stylesheet" href="css/tableexport.min.css" />
		<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
		<script type="text/javascript" src="laydate/laydate.js" ></script>
		<script type="text/javascript" src="js/js.js" ></script>
		<script src="https://cdn.bootcss.com/jquery/2.1.0/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<title>待发货</title>
		<script src="../js/ajaxFunction.js" type="text/javascript" charset="utf-8"></script>
		<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
		<script src="js/xlsx.core.min.js"></script>
		<script src="js/blob.js"></script>
		<script src="js/FileSaver.min.js"></script>
		<script src="js/tableexport.js"></script>
		<style>
			*{font-size:1em;}
		</style>
		<script>
			$(function(){
				page = 1; // 当前页数
				totalpage = 1;// 总页数
				getTaskInfo(1);
				orderNumber = "";
			});
			function getTaskInfo(spage){
				page = spage;
				page = page > totalpage ? totalpage : page;
				page = page < 1 ? 1 : page;
				$.ajax({
					url : '../TaskInfoServlet',
					method : 'post',
					dataType : 'json',
					data : {
						'condition' : 'alltask', 
						'page' : page, 
						'startTime' : $('#beginDate').val(), 
						'endTime' : $('#endDate').val(),
						'taskno' : $('#taskno').val(),
						'transportStatus' : "1",
						'applyStatus' : "2",
						'lackStatus' : "1",
						'addressee' : $('#addressee').val()
						},
					success : function(tasks) {
						var str = "<tr>" + 
						"				<th><input type=\"checkbox\" onclick=\"swapCheck()\"/></th>" + 
						"				<th>下单时间</th>" + 
						"				<th>订单号</th>" + 
						"				<th>用户QQ</th>" + 
						"				<th>收件人</th>" + 
						"				<th>电话</th>" + 
						"				<th>地址</th>" + 
						"				<th>商品</th>" + 
						"				<th>订单金额</th>" + 
						"				<th>总价</th>" + 
						"				<th>付款编号</th>" + 
						"				<th>状态信息</th>" + 
						"			</tr> ";
						$.each(tasks, function(index,task,array){
							if (task.total == null){
								var oldTime = (new Date(task.time)).getTime();
							    var curTime = new Date(oldTime).Format("yyyy-MM-dd");
								str += "<tr class=\"tr_vertical_align\">" + 
								"					<td class=\"tb_tr_center\"><input type=\"checkbox\" name='taskno' value='"+task.no+"'/></td>" + 
								"					<td class=\"tb_tr_center\">"+curTime+"</td>" + 
								"					<td class=\"tb_tr_center\">"+task.no+"</td>" + 
								"					<td class=\"tb_tr_center\">"+task.user.qq+"</td>" + 
								"					<td class=\"tb_tr_center\">"+task.addressee+"</td>" + 
								"					<td class=\"tb_tr_center\">"+task.tel+"</td>" + 
								"					<td class=\"tb_tr_center\">"+task.addr+"</td>" + 
								"					<td><img width='100' height='100' src=\"../"+task.goods.pic+"\" class=\"pic100 fl\" />" + 
								"				<div class=\"fl ml10\">" + 
								"					名称 : "+task.goods.name+"<br />"+
								"					品牌 : "+task.goods.brand+"<br /> 型号 : "+task.goods.type+" <br /> <span class=\"blue_span\">原价 : "+task.goods.price+"</span> <br />" + 
								"					颜色 : "+task.goods.color+" <br /> 尺码 : <span class=\"blue_span\">"+task.goods.size+"</span> <br /> 数量 : "+task.goodsNumber+" <br />" + 
								"				</div></td>" + 
								"					<td class=\"tb_tr_center\">" + 
								"						<div class=\"ml10\">" + 
								"							<div>商品单价 : <span>"+task.price+"</span></div>" + 
								"							<div>国际运费 : <span>"+task.freight+"</span></div>";
								var row = 0;
								for (var i = 0; index + i < tasks.length && tasks[index + i].payNo == task.payNo; i++)
									row++;
								if (index == 0 || index > 0 && tasks[index-1].payNo != task.payNo){
									str += "<td rowspan='"+row+"'>总价: <span class=\"red_span\">￥"+task.totalPrice+"</span>" + 
									"				</td><td rowspan='"+row+"'><br /> 付款编号:"+task.payNo+" <br />";
								}
								str += "			</td><td>";
								switch(task.transportStatus){
								case '1': str += "<span class=\"red_span\">未发货</span> <br />";break;
								case '2': str += "<span class=\"red_span\">在途</span>  <br />";break;
								case '3': str += "<span class=\"red_span\">已到货</span>  <br />";break;
								case '4': str += "<span class=\"red_span\">已发货</span>  <br />";break;
								}
								switch(task.payStatus){
								case '1': str += "未付款<br />";break;
								case '2': str += "已付款   <br />";break;
								case '3': str += "已退款  <br />";break;
								}
								switch(task.applyStatus){
								case '1': str += "未申请发货  <br />";break;
								case '2': str += "已申请发货  <br />";break;
								}
								switch(task.lackStatus){
								case '1': str += "不缺货  <br />";break;
								case '2': str += "缺货  <br />";break;
								}
								switch(task.isPayFreight){
								case '1': str += "国内运费已付  <br />";break;
								case '0': str += "国内运费未付  <br />";break;
								}
								str += "</td></tr>" ;
							}else{
								totalpage = task.total / 3;
								totalpage = totalpage > parseInt(totalpage) ? parseInt(totalpage) + 1 : totalpage;
								$('#total').empty();
								$('#total').append(task.total);
								$('#curpage').empty();
								$('#curpage').append(page);
								$('#totalpage').empty();
								$('#totalpage').append(totalpage);
							}
						})
						$('#taskTable').empty();
						$('#taskTable').append(str);//class='red_span'
						// 表格导出
						$.fn.tableExport.xlsx = {
						    defaultClass: "xlsx",
						    buttonContent: "导出发货信息",
						    mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
						    fileExtension: ".xlsx"
						};
						$("#taskTable").tableExport({
						    headings: true, 
						    footers: true, 
						    formats: ["xlsx"],
						    fileName: "发货信息",
						    bootstrap: true,
						    position: "bottom",
						    ignoreRows: null,
						    ignoreCols: [1,2,3,7,8,9,10,11,12]
						});
					}
				});
			}
			function order(operation){
				if ($("input[name=taskno]:checked").length == 0){
					alert('请先选择需要操作的订单！');
					return;
				}
				var tasknos = [];
				$("input[name=taskno]:checked").each(function (index, item){
					tasknos.push($(this).val());
				});
				$.ajax({
					url : '../DeliveryOperationServlet',
					method : 'post',
					data : {
						'operation' : operation,
						'tasknos' : tasknos, 
						'deliveryno' : $('#orderNumber').val(),
						'payNo' : $('#payNo').val(),
						'freight' : $('#freight').val()
					},
					traditional:true,
					success : function() {
						alert('操作成功！');
						getTaskInfo(1);
					}
				});
				$('#closeButton').click();
			}
		</script>
	</head>
	<body>
		<div class="main border-bottom-gray"><span class="fontBold"><a href="" class="mapsite">首页</a></span>&nbsp;/&nbsp;
		<span class="fontBold"><a href="" class="mapsite">发货管理</a></span>&nbsp;/&nbsp;待发货列表</div>
		<div class="border-bottom-gray main">
			<form action="" method="post">
				<div class="padding10_0">
					<span class="fontBold fontsize12">收件人 : </span><input id="addressee" type="text" class="input_text"  placeholder="请输入收件人"/>&nbsp;&nbsp;
					<span class="fontBold fontsize12">订单编号 : </span><input id="taskno" type="text" class="input_text"  placeholder="请输入订单编号"/>&nbsp;&nbsp;
					<span class="fontBold fontsize12">订单日期选择 : </span><input type="text" class="input_text" placeholder="请开始选择日期" id="beginDate"/>&nbsp;
					<span  class="fontBold fontsize12">至</span>&nbsp;
					<input type="text" class="input_text" placeholder="请选择截至日期" id="endDate"/>&nbsp;&nbsp;
					<input type="button" onclick="getTaskInfo(1)" class="input_submit" value="查询"/>&nbsp;&nbsp;
					<input type="reset" class="whitebutton" value="重置"/>
				</div>
			</form>
		</div>
		<div class="main graybg">
			<form>
			<table class="tb_wid" id="taskTable">
			</table>
			</form>
			<div class="fl padding10_0">
				<!-- <input type="button" class="input_submit" value="信息导出"/> -->
				<input type="button" class="input_submit" value="已发货" onclick="$('#first').click()"/>
			</div>
			<!-- <div align="left" valign="top" class="fenye">
				<span id="total"></span>条数据 <span id="curpage"></span>/<span id="totalpage"></span> 页&nbsp;&nbsp;
				<a href="javascript:void(0)" target="mainFrame" onfocus="this.blur()" onclick="getTaskInfo(1)">首页</a>&nbsp;&nbsp;
				<a href="javascript:void(0)" target="mainFrame" onfocus="this.blur()" onclick="getTaskInfo(--page)">上一页</a>&nbsp;&nbsp;
				<a href="javascript:void(0)" target="mainFrame" onfocus="this.blur()" onclick="getTaskInfo(++page)">下一页</a>&nbsp;&nbsp;
				<a href="javascript:void(0)" target="mainFrame" onfocus="this.blur()" onclick="getTaskInfo(totalpage)">尾页</a>
	        </div> -->
		</div>
		<input id="first" type="button" style="display:none;" data-toggle="modal" data-target="#myModal1"/>
		<!-- 模态框（Modal） -->
		<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							&times;
						</button>
						<h4 class="modal-title" id="myModalLabel">
							请输入发货信息：
						</h4>
					</div>
					<div class="modal-body">
						<table style="font-size:1.2em;height:180px;margin: 0 auto;">
							<tr>
								<td>发货单号：</td>
								<td><input id="orderNumber" type="text" /></td>
							</tr>
							<tr>
								<td>国内运费：</td>
								<td><input id="freight" type="text" /></td>
							</tr>
							<tr>
								<td>付款编号：</td>
								<td><input id="payNo" type="text" /></td>
							</tr>
						</table>
					</div>
					<div class="modal-footer">
						<button id="closeButton" type="button" class="btn btn-default" data-dismiss="modal">关闭
						</button>
						<button type="button" class="btn btn-primary" onclick="order('deliveried')">
							确定
						</button>
					</div>
				</div><!-- /.modal-content -->
			</div><!-- /.modal -->
		</div>
	<script>
		laydate.render({
		  elem: '#endDate'
		});
		laydate.render({
		  elem: '#beginDate'
		});
	</script>
	</body>
</html>
